package edu.upenn.yas;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/** Action taken when a user requests to see an asdf. */
public class ASDF extends ActionSupport {

    private Float score;
    public Float getScore() { return score; }

    private Integer uid;
    public Integer getUID() { return uid; }

    private String username;
    public String getUsername() { return username; }

    private String title;
    public String getTitle() { return title; }
    
    private String datetime;
    public String getDateTime() { return datetime; }

    private String content;
    public String getContent() { return content; }

    private String url;
    public String getURL() { return url; }

    private String numViews;
    public String getNumViews() { return numViews; }

    private List<CommentTriples> comments = null;

    public String execute() {
        Map session = ActionContext.getContext().getSession();
        uid = (Integer)session.get("uid");

	  if (session.get("login") != null) {
            String username = (String)session.get("username");
            List<String> getAsdf =
                QueryEngine.instance.GetASDF(uid);
            username = getAsdf.get(0);
            title = getAsdf.get(1);
            datetime = getAsdf.get(2);
            content = getAsdf.get(3);
            url = getAsdf.get(4);
            numViews = getAsdf.get(5);
		score = QueryEngine.instance.GetRating(uid);
            comments = QueryEngine.instance.getComments(uid);
            return SUCCESS;
        } else {
            return ERROR;
        }

    }

    public List<CommentTriples> getComments() { return comments ; }
    public void setComments(List<CommentTriples > comments) {
        this.comments  = comments;
    }

    public static class CommentTriples {
        private String level;
        public String getLevel() { return level; }
        private String username;
        public String getUsername() { return username; }
        private String body;
        public String getBody() { return body; }
        public CommentTriples (String level, String username, String body) {
            this.level= level;
            this.username= username;
            this.body= body;
        }
    }


}
